TARGET=OTPAddInNative.so

SOURCES=AddInNative.cpp \
	dllmain.cpp \
	PythonAddin.cpp \
	stdafx.cpp

LIBS=pthread dl util m

OBJECTS=$(SOURCES:.cpp=.o)
INCLUDES=-I../include -I/usr/include/python2.6
CXXLAGS=$(CXXFLAGS) $(INCLUDES) -finput-charset=WINDOWS-1251 -fPIC
LDFLAGS=-Wl,-O1 -Wl,--as-needed -L.
LINKFORSHARED=-Xlinker -export-dynamic

ifndef FROZEN
LIBS += python2.6
endif

all: $(TARGET)

-include $(OBJECTS:.o=.d)

%.o: %.cpp
	g++ -c  $(CXXLAGS) $*.cpp -o $*.o
	g++ -MM $(CXXLAGS) $*.cpp >  $*.d
	@mv -f $*.d $*.d.tmp
	@sed -e 's|.*:|$*.o:|' < $*.d.tmp > $*.d
	@sed -e 's/.*://' -e 's/\\$$//' < $*.d.tmp | fmt -1 | \
	  sed -e 's/^ *//' -e 's/$$/:/' >> $*.d
	@rm -f $*.d.tmp

$(TARGET): $(OBJECTS) Makefile
ifdef FROZEN
	g++ $(CXXLAGS) $(LDFLAGS) $(LINKFORSHARED) -shared $(OBJECTS) /usr/lib/libpython2.6.a $(addprefix -l, $(LIBS)) -o $(TARGET)
else
	g++ $(CXXLAGS) $(LDFLAGS) $(LINKFORSHARED) -shared $(OBJECTS) $(addprefix -l, $(LIBS)) -o $(TARGET)
endif

clean:
	-rm $(TARGET) *.o *.d
